package main;

import p2p.Config;
import p2p.FileList;
import p2p.Kwalker;
import p2p.NeighborList;
import p2p.PeerPool;

import server.RMIServer;

public class UpdateThread implements Runnable {
	private Thread runner;
	private PeerPool peerPool;
	private NeighborList neighborList;
	private FileList fileList;
//	private Kwalker kWalker;
	private static boolean run = true;

	public UpdateThread(String threadName, RMIServer s, p2p.Peer thisPeer, PeerPool peerPool, NeighborList neighborList, FileList fileList/*, Kwalker kWalker*/) {
		this.peerPool = peerPool;
		this.neighborList = neighborList;
		this.fileList = fileList;
//		this.kWalker = kWalker;
		
		runner = new Thread(this, threadName); // (1) Create a new thread.
		runner.start(); // (2) Start the thread.
	}
	
	public void run() {
		while(run) {
			try {
				Thread.sleep(Config.UpdateInterval);
				peerPool.update();
				neighborList.update();
				fileList.update();
//				kWalker.update();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void stopThread(){
		run = false;
	}
}